/*
 *  preparar_nota_nueva.cpp
 *  Wilson
 *
 *  Created by Sebastian Orfino on 10/6/11.
 *  Copyright 2011 Sol90Labs. All rights reserved.
 *
 */
#include "VCPlugInHeaders.h"

//project includes
#include "preparar_nota_nueva.h"
#include "xmp_facade.h"

//stl includes
#include "adobe/zuid.hpp"
#include "boost/date_time/posix_time/posix_time.hpp" //include all types plus i/o
#include "boost/date_time/time_clock.hpp"
#include "boost/format.hpp"
#include <sstream>
#include <fstream>
#include <string>
#include "pugixml.hpp"

using namespace eventos;
preparar_nota_nueva::preparar_nota_nueva()
{
	using namespace boost;
	using namespace boost::posix_time;
	
	//adobe::zuid_t uid;
	//id_payload_ = uid.str();
	
	timestamp_ = to_iso_string(second_clock::universal_time());
}

std::string preparar_nota_nueva::payload() const
{
	//using namespace boost;
	using namespace std;
	using namespace pugi;
	using namespace xmp;
	
	ostringstream ostr;
	xml_document xml_doc;
	if (xml_doc.load("<payload></payload>")) {
	
		xml_node payload_n = xml_doc.child("payload");
		payload_n.append_attribute("mensaje") = ID();
		
		xml_node id_n = payload_n.append_child(info_nota_t::id_tag());
		xml_node creador_n = payload_n.append_child(info_nota_t::creador_tag());
		xml_node timestamp_n = payload_n.append_child(info_nota_t::cuando_tag());
		
		id_n.append_child(node_pcdata).set_value(id_payload_.c_str());
		creador_n.append_child(node_pcdata).set_value(uname_.c_str());
		timestamp_n.append_child(node_pcdata).set_value(timestamp_.c_str());
		
		
		xml_doc.save(ostr);
	}
	return ostr.str();
}
